﻿CREATE PROCEDURE [dbo].[UpdatePersonMark]
	@Mark uniqueidentifier,
    @Person uniqueidentifier,
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE PersonMark

	SET 
	 
     Mark = @Mark,
     Person = @Person,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
 	 LastChangedBy = @LastChangedBy

	WHERE Mark = @Mark AND Person=@Person AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM PersonMark 

	WHERE Mark = @Mark AND Person = @Person

RETURN 0